home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** File: WSTGS.c
- ** Written by: Eric Soldan
- **
- ** Copyright © 1990-1993 Apple Computer, Inc.
- ** All rights reserved.
- */
-
- /* You may incorporate this sample code into your applications without
- ** restriction, though the sample code has been provided "AS IS" and the
- ** responsibility for its operation is 100% yours. However, what you are
- ** not permitted to do is to redistribute the source as "DSC Sample Code"
- ** after having made changes. If you're going to re-distribute the source,
- ** we require that you make it clear in the source that the code was
- ** descended from Apple Sample Code, but that you've made changes. */
-
-
-
- /*****************************************************************************/
-
-
-
- #include "App.h" /* Get the application includes/typedefs, etc. */
- #include "App.defs.h" /* Get various application definitions. */
- #include "App.protos.h" /* Get the prototypes for the application. */
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __TEXTEDITCONTROL__
- #include "TextEditControl.h"
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __UTILITIES__
- #include "Utilities.h"
- #endif
-
-
- /*****************************************************************************/
-
-
-
- static void STGSContentClick(WindowPtr window, EventRecord *event, Boolean firstClick);
- static Boolean STGSContentKey(WindowPtr window, EventRecord *event, Boolean *passThrough);
- static OSErr STGSImageDocument(FileRecHndl frHndl);
- static OSErr STGSInitContent(FileRecHndl frHndl, WindowPtr window);
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- OSErr STGSInitDocument(FileRecHndl frHndl);
- OSErr STGSInitDocument(FileRecHndl frHndl)
- {
- FileRecPtr frPtr;
-
- frPtr = *frHndl;
- frPtr->fileState.calcFrameRgnProc = nil;
- frPtr->fileState.contentClickProc = STGSContentClick;
- frPtr->fileState.contentKeyProc = STGSContentKey;
- frPtr->fileState.drawFrameProc = nil;
- frPtr->fileState.freeDocumentProc = nil;
- frPtr->fileState.freeWindowProc = nil;
- frPtr->fileState.imageProc = STGSImageDocument;
- frPtr->fileState.initContentProc = STGSInitContent;
- frPtr->fileState.readDocumentProc = nil;
- frPtr->fileState.readDocumentHeaderProc = nil;
- frPtr->fileState.resizeContentProc = nil;
- frPtr->fileState.scrollFrameProc = nil;
- frPtr->fileState.undoFixupProc = nil;
- frPtr->fileState.windowCursorProc = nil;
- frPtr->fileState.writeDocumentProc = nil;
- frPtr->fileState.writeDocumentHeaderProc = nil;
-
- return(noErr);
- }
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- static void STGSContentClick(WindowPtr window, EventRecord *event, Boolean firstClick)
- {
- #pragma unused (firstClick)
-
- short cnum;
- ControlHandle ctl;
-
- if (cnum = IsCtlEvent(window, event, &ctl, nil)) {
-
- }
- }
-
-
-
- /*****************************************************************************/
-
-
-
- static Boolean STGSContentKey(WindowPtr window, EventRecord *event, Boolean *passThrough)
- {
- #pragma unused (passThrough)
-
- ControlHandle ctl;
- Str255 str;
- WindowPtr ww;
- FileRecHndl ff;
- short v;
-
- if (IsCtlEvent(window, event, nil, nil) == -1) {
- ww = GetNextWindow(nil, kDocFileType);
- if (ww) {
- ff = (FileRecHndl)GetWRefCon(ww);
- CNum2Ctl(window, 101, &ctl);
- CTEGetPStr(ctl, str);
- if (pcmp((*ff)->d.doc.testStr, str)) {
- (*ff)->d.doc.newImage = true;
- pcpy((*ff)->d.doc.testStr, str);
- }
- CNum2Ctl(window, 102, &ctl);
- CTEGetPStr(ctl, str);
- v = p2dec(str, nil);
- if ((*ff)->d.doc.minSize != v) {
- (*ff)->d.doc.newImage = true;
- (*ff)->d.doc.minSize = p2dec(str, nil);
- }
- CNum2Ctl(window, 103, &ctl);
- CTEGetPStr(ctl, str);
- (*ff)->d.doc.maxSize = p2dec(str, nil);
- BeginContent(ww);
- DoImageDocument(ff);
- EndContent(ww);
- SetDocSize(ff, kwNoChange, (*ff)->d.doc.docSize);
- }
- }
- return(true);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- #pragma segment STGSPalette
- static OSErr STGSImageDocument(FileRecHndl frHndl)
- {
- #pragma unused (frHndl)
-
- DoDrawControls((*frHndl)->fileState.window, false);
- return(noErr);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- #pragma segment STGSPalette
-
- static Boolean DigitFilter(TEHandle te, EventRecord *event, short *handled);
- static Boolean DigitFilter(TEHandle te, EventRecord *event, short *handled)
- {
- #pragma unused (te, handled)
-
- char key;
- short i;
-
- key = event->message & charCodeMask;
- i = event->modifiers & keyCodeMask;
- if (i & cmdKey) return(false);
- if (i & optionKey) return(false);
- if (key == 8) return(false);
- if (key == 9) return(false);
- if ((key >= 28) && (key <= 31)) return(false);
-
- if ((key < '0') || (key > '9')) return(true);
-
- return(false);
- }
-
- OSErr STGSInitContent(FileRecHndl frHndl, WindowPtr window)
- {
- OSErr err;
- ControlHandle ctl;
- short i;
-
- err = AddControlSet(window, (*frHndl)->fileState.sfType, kwStandardVis, 0, 0, nil);
- for (i = 102; i <= 103; ++i) {
- CNum2Ctl(window, 102, &ctl);
- if (ctl)
- CTESetKeyFilter((TEHandle)GetCRefCon(ctl), DigitFilter);
- }
-
- return(err);
- }
-
-
-
-